import datetime

from sqlalchemy import ForeignKey, String, func
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.application.payment.enums import PaymentStatus
from src.infrastructure.db.models.base import Base


class Payment(Base):
    __tablename__ = "payment"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    summ: Mapped[float] = mapped_column(nullable=False)
    bill_id: Mapped[str] = mapped_column(String(50))
    status: Mapped[PaymentStatus] = mapped_column(
        server_default="waiting_payment",
    )
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))
    user = relationship("User", back_populates="payments")
    created_at: Mapped[datetime.datetime] = mapped_column(server_default=func.now())

    def __repr__(self):
        return f"<Payment №{self.id} {self.summ}$>"

    def __str__(self):
        return self.__repr__()
